package com.lw.system.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.lw.common.basemodel.EasyuiModel;
import com.lw.common.basemodel.Json;
import com.lw.common.core.service.BaseServiceI;
import com.lw.common.util.ModelConvertUtil;
import com.lw.common.web.controller.BaseController;
import com.lw.system.model.Role;
import com.lw.system.service.RoleService;

/**
 * 
 * @Title: RoleController.java
 * @Package com.lw.controller
 * @Description:角色资源
 * @author 刘伟 15818570028@163.com
 * @date 2016年12月21日 下午6:58:08
 * @version V1.0
 */
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<Role, String> {

	@javax.annotation.Resource
	private RoleService roleService;

	@Override
	public BaseServiceI<Role, String> getBaseService() {
		return roleService;
	}

	@RequestMapping(value = "/findRoleResources", method = RequestMethod.GET)
	public EasyuiModel<Role> findRoleResources(Role role, int page, int rows) {
		return ModelConvertUtil.pageInfo2EasyuiModel(roleService.findRoleAndResources(role, page, rows));
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Json add(Role role) {

		return roleService.add(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/remove", method = RequestMethod.POST)
	public Json remove(String id) {
		return roleService.remove(id) > 0 ? setSimpleSuccess(id) : setFailed();

	}

	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Json edit(Role role) {

		return roleService.edit(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/combogrid", method = RequestMethod.GET)
	public EasyuiModel<Role> combogrid(Role role, int page, int rows) {
		return ModelConvertUtil.pageInfo2EasyuiModel(roleService.findRoleAndResources(role, page, rows));
	}

	@RequestMapping(value = "/editMenu", method = RequestMethod.POST)
	public Json editMenu(Role role) {

		return roleService.editMenu(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/getMenuIdsByPrimaryKey", method = RequestMethod.GET)
	public Json getMenuIdsByPrimaryKey(String roleId) {
		return setSimpleSuccess(roleService.getMenuIdsByPrimaryKey(roleId));
	}

}
